#include <stdio.h>
//void to_binary(unsigned long n);
void to_base_n(unsigned long,int);
int main(void)
{
	unsigned long number;
	int jin;
	printf("Enter an interger (q to quit):\n");
	while(scanf("%lu%d",&number,&jin) == 2)
	{
//		to_binary(number);
		to_base_n(number,jin);
		putchar('\n');
	}
	
	return 0;	
}
//void to_binary(unsigned long n)
//{
//	int r;
//	
//	r=n%2;
//	if(n>=2)
//		to_binary(n/2);
//	putchar(r == 0?'0':'1');
//	
//	return;	
//} 
void to_base_n(unsigned long n,int j)
{
	int r;
	
	r=n%j;
	if(n>=j)
		to_base_n(n/j,j);
	printf("%d",r);
	return;	
}
